package cn.tedu.property_management_system.controller;

import cn.tedu.property_management_system.entity.DTO.RepairAddNewDTO;
import cn.tedu.property_management_system.entity.RepairType;
import cn.tedu.property_management_system.entity.VO.RepairVO;
import cn.tedu.property_management_system.service.IRepairService;
import cn.tedu.property_management_system.utils.JsonResult;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("repair")
public class RepairController {
    @Autowired
    IRepairService repairService;

    @GetMapping("loadRepair/{pageNum}/{PageSize}")
    public JsonResult loadRepair(
            @PathVariable("pageNum")Integer pageNum,@PathVariable("PageSize")Integer PageSize) {
        PageInfo<RepairVO> pageInfo= repairService.loadRepair(pageNum,PageSize);
        return JsonResult.OK(pageInfo);
    }

    @GetMapping("loadRepair/personal")
    public JsonResult<List<RepairVO>> loadPersonalRepair() {
        log.debug("根据当前用户查询报修列表");
        List<RepairVO> list=repairService.loadPersonalRepair();
        return JsonResult.OK(list);
    }

    @GetMapping("loadRepairType")
    public JsonResult loadRepairType() {
        List<RepairType> repairTypes = repairService.loadRepairType();
        return JsonResult.OK(repairTypes);
    }

    @PostMapping("deleteRepair")
    public JsonResult deleteRepair(@RequestBody Integer... ids) {
        repairService.deleteRepair(ids);
        return JsonResult.OK();
    }

    @GetMapping("handleRepair/{id}")
    public JsonResult handleRepair(@PathVariable("id") Integer id){
        repairService.handleRepair(id);
        return JsonResult.OK();
    }

    @GetMapping("screenRepair/{repId}/{status}")
    public JsonResult screenRepair(
            @PathVariable Integer repId,
            @PathVariable Integer status
    ){
        List<RepairVO> repairVOS = repairService.screenRepair(repId, status);
        return JsonResult.OK(repairVOS);
    }

    @PostMapping("addRepair")
    public JsonResult insert(@RequestBody RepairAddNewDTO repairAddNewDTO){
        repairService.insert(repairAddNewDTO);
        return JsonResult.OK();
    }
}
